package com.zhentao.ai.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

/**
 * 置信区间
 * @author zhentao
 * @date 2024-12-19
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ConfidenceInterval {
    
    /**
     * 下限
     */
    private BigDecimal lowerBound;
    
    /**
     * 上限
     */
    private BigDecimal upperBound;
    
    /**
     * 置信水平 (如90、95、99)
     */
    private Integer confidenceLevel;
    
    /**
     * 检查值是否在置信区间内
     */
    public boolean contains(BigDecimal value) {
        return value.compareTo(lowerBound) >= 0 && value.compareTo(upperBound) <= 0;
    }
    
    /**
     * 获取区间宽度
     */
    public BigDecimal getWidth() {
        return upperBound.subtract(lowerBound);
    }
    
    /**
     * 获取区间中点
     */
    public BigDecimal getMidpoint() {
        return lowerBound.add(upperBound).divide(BigDecimal.valueOf(2));
    }
}

